package com.smit.dvb.ci;

import com.smit.adapter.DVBAdapter;
import com.smit.dvb.CIData;
import com.smit.dvb.CIMenuInfo;
import com.smit.dvb.CIPinInfo;
import com.smit.utils.LogUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * DVB CI控制
 */
public class CIControl {
    /** CIData 数据更新 */
    public static final int MSG_CI_DATA_UPDATED = 101;
    /** 显示CI菜单 */
    public static final int MSG_CI_SHOW_MMI_MENU = 102;
    /** 更新CI菜单 */
    public static final int MSG_CI_UPDATE_MMI_MENU = 103;
    /** 隐藏CI菜单 */
    public static final int MSG_CI_HIDE_MMI_MENU = 104;
    /** 显示密码输入对话框 */
    public static final int MSG_CI_SHOW_PIN_DIALOG = 105;
    /** 隐藏密码输入对话框 */
    public static final int MSG_CI_HIDE_PIN_DIALOG = 106;

    private static final String TAG = "CIControl";
    private final List<ICICallback> ciCallbackList = new ArrayList<ICICallback>();

    /**
     * <p> 添加一个CI回调 <br/>
     * @param callback 回调接口
     */
    public void addCallback(ICICallback callback) {
        if (!ciCallbackList.contains(callback)) {
            ciCallbackList.add(callback);
        }
    }

    /**
     * <p> 移除一个CI回调 <br/>
     * @param callback 回调接口<br/>
     */
    public void removeCallback(ICICallback callback) {
        if (ciCallbackList.contains(callback)) {
            ciCallbackList.remove(callback);
        }
    }

    /**
     * <p> 获取所有CI回调对象 <br/>
     * @return 返回所有注册进来的回调
     */
    public List<ICICallback> getCallbackList() {
        return ciCallbackList;
    }

    /**
     * 打开CI会话
     */
    public void openSession() {
        LogUtil.info(TAG, "openSession start>>>");
        DVBAdapter.getInstance().getDVBManager().getDVBService().openSession();
    }

    /**
     *  关闭会话
     */
    public void closeSession() {
        DVBAdapter.getInstance().getDVBManager().getDVBService().closeSession();
    }

    /**
     * 选择CI Menu选项
     * @param index 选项索引
     */
    public void selectMenuItem(int index) {
        DVBAdapter.getInstance().getDVBManager().getDVBService().selectMenuItem(index);
    }

    /**
     * 设置MMI密码
     * @param pin 密码
     */
    public void setPin(String pin) {
        DVBAdapter.getInstance().getDVBManager().getDVBService().setPin(pin);
    }

    /**
     * 获取CI Menu显示信息
     * @return CIMenuInfo 对象
     */
    public CIMenuInfo getCIMenuInfo() {
        return DVBAdapter.getInstance().getDVBManager().getDVBService().getCIMenuInfo();
    }

    /**
     * 获取CI Pin信息
     * @return CIPinInfo 对象
     */
    public CIPinInfo getCIPinInfo() {
        return DVBAdapter.getInstance().getDVBManager().getDVBService().getCIPinInfo();
    }

    /**
     * 328020051##MLTCA-ORDGRC-1.0.3-3##No Smart Card
     * @return 返回CI信息
     */
    public CIData getSmartCardInfo() {
        return DVBAdapter.getInstance().getDVBManager().getDVBService().getSmartCardInfo();
    }

    /**
     * hardwareInfo=hardware:5.6.3.2##software_model:2000##cacode:00
     * ##customized:N##operator:Generic##DTMB:Y##DT_check:N
     * ##descramble_channel:1##ciplus:N##secure:N
     * @return 返回固件信息
     */
    public CIData getHardwareInfo() {
        return DVBAdapter.getInstance().getDVBManager().getDVBService().getHardwareInfo();
    }

    /**
     * 返回设备ID信息
     * @return 设备ID信息
     */
    public String getDeviceId() {
        return DVBAdapter.getInstance().getDVBManager().getDVBService().getDeviceId();
    }

    /**
     * 返回设备Type信息
     * @return 设备Type信息
     */
    public String getDeviceType() {
        return DVBAdapter.getInstance().getDVBManager().getDVBService().getDeviceType();
    }
}